package com.houseman.workFlow.utils;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * 数据库信息集
 */
public class DBUtils {

	public static final String url = "jdbc:mysql://127.0.0.1:3306/workflow";
	public static final String username = "root";
	public static final String password = "root";
	
	/**
	 * 获得Connection
	 * @return
	 */
	public static Connection geConnection() throws Exception {
		Class.forName("com.mysql.jdbc.Driver");
		
		return DriverManager.getConnection(url, username, password);
	}
	
	/**
	 * 关闭数据库连接
	 */
	public static void close(Connection conn, PreparedStatement ps, ResultSet rs) {
		
		try {
			conn.close();
			ps.close();
			rs.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * 关闭数据库连接
	 */
	public static void close(Connection conn, PreparedStatement ps) {
		
		try {
			conn.close();
			ps.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
}
